function plt_er(tsdat,stepdat,fitdat,core,nsteps,titlestr)
%function plt_er(tsdat,stepdat,fitdat,core,nsteps,titlestr)
%
% Plot Erosion rate figure with fits to each step
%
% Modified from plt_erosionrate.m originally by Steve Suttles
%
% Modified by Patrick Dickhudt Dec. 2010
% - remove evals
% - modify plotting in loop portion to accomodate changes in other routines
    
figure
ax11=axes( 'Xcolor', 'k','Ycolor','b','Xaxislocation','bottom',...
    'Yaxislocation','left') 
set(gca,'outerposition',[0.02 0.02 .93 .93])    
line(tsdat.etime,tsdat.E,'color','b','Parent',ax11,'linewidth',1.2);
set(gca,'yscale','log');
set(gca,'xlim',[0 max(tsdat.etime)])
ylabel('Erosion Rate, [kg ^. s^{-1} ^. m^{-2}]','color','b')
xlabel('time, [s]')
%set ylimits for E
set(ax11,'ylim',[1e-8 1e-3])


hold on;
          
%make loop to plot lambda fits
for i1 = 1:nsteps
    stpind = stepdat.idx.(['step' num2str(i1)]);
    t = fitdat(i1).tmin:fitdat(i1).tmax;    
    x = t+tsdat.etime(min(stpind));
    
  a=fitdat(i1).E0;
  b=fitdat(i1).lambda;

  if b <= 1e-9
      a=mean(tsdat.E(stpind));
      b=1e-9;
  end
  plot(x,a.*exp(-b.*t),'-k','linewidth',1.2)

end

hold off
                  


ax12 = axes('Position', get(ax11, 'Position'),'Xaxislocation','top',...
       'color','none','Yaxislocation','right','Xcolor','k','Ycolor',...
       'r')

line(tsdat.etime, tsdat.tau,'color','r','linewidth',1.5 ,'Parent',ax12);
set(gca,'xlim',[0 max(tsdat.etime)])
set(gca,'xticklabel',[ ])
set(gca,'ylim',[0 0.7])
ylabel('{\tau}, [Pa]')
       
title(['core ' titlestr])
set(gcf,'name','Erosion Rate')

saveas(gcf,[core '_er'],'fig')
            
            
            
            